<?php

namespace app\api\middleware;

use app\api\service\UserVisitService;
use Closure;

class UserVisitLog
{
    /**
     * 用户浏览日志
     * @param $request
     * @param Closure $next
     * @return bool|void
     */
    public function handle($request, Closure $next)
    {
        $startTime = app()->getBeginTime();
        $response  = $next($request);
        $endTime   = microtime(true);

        // 记录操作日志
        if(!$request->isGet()) {
            (new UserVisitService)->addVisitLog($request, $request->userInfo, $response, $startTime, $endTime);
        }

        return $response;
    }
}
